package com.swanclouds.redfish.task.domain;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.swanclouds.model.task.Task;
import com.swanclouds.redfish.common.redfish.Status;

import java.util.List;
import java.util.Map;

/**
 * @author 李文强
 * description 服务器当前任务服务资源信息实体类
 */
public class TaskModel implements Task {

    //当前任务资源的访问路径
    @JsonProperty("@odata.id")
    private String dataId;

    //任务服务资源模型的OData描述信息
    @JsonProperty("@odata.context")
    private String context;

    //任务服务资源的类型
    @JsonProperty("@odata.type")
    private String type;

    //任务服务资源的ID
    @JsonProperty("Id")
    private String id;

    //任务服务资源的名称
    @JsonProperty("Name")
    private String name;

    //系统时间
    @JsonProperty("DataTime")
    private String dataTime;

    /**
     * 对已完成的任务的处理方
     * 法。
     * ● Oldest：新任务覆盖最
     * 早的任务
     * ● Manual：不进行覆盖
     */
    @JsonProperty("CompletedTaskOverWritePolicy")
    private String completedTaskOverWritePolicy;

    //任务服务资源的描述信息
    @JsonProperty("Description")
    private String description;

    /**
     * 任务状态变化时是否上报
     * 事件。
     * ● true
     * ● false
     */
    @JsonProperty("LifeCycleEventOnTaskStateChange")
    private Boolean lifeCycleEventOnTaskStateChange;

    //任务服务使能状态。
    @JsonProperty("ServiceEnabled")
    private Boolean serviceEnabled;

    /**
     * 任务服务资源的状态，包
     * 括：
     * ● Status：使能状态
     * ● Health：健康状态
     * ● Severit
     */
    @JsonProperty("Status")
    private List<Status> status;

     //任务列表
    @JsonProperty("Members")
    private List<Map<String,Object>> members;

    //当前运行的任务数量
    @JsonProperty("Members@odata.count")
    private Integer membersCount;

    //任务列表
    @JsonProperty("Tasks")
    private List<Map<String,Object>> tasks;

    @Override
    public String getDataId() {
        return this.dataId;
    }

    @Override
    public String getContext() {
        return this.context;
    }

    @Override
    public String getType() {
        return this.type;
    }

    @Override
    public String getId() {
        return this.id;
    }

    @Override
    public String getName() {
        return this.name;
    }

    public String getDataTime() {
        return dataTime;
    }

    public String getCompletedTaskOverWritePolicy() {
        return completedTaskOverWritePolicy;
    }

    public String getDescription() {
        return description;
    }

    public Boolean getLifeCycleEventOnTaskStateChange() {
        return lifeCycleEventOnTaskStateChange;
    }

    public Boolean getServiceEnabled() {
        return serviceEnabled;
    }

    public List<Status> getStatus() {
        return status;
    }

    public List<Map<String, Object>> getMembers() {
        return members;
    }

    public Integer getMembersCount() {
        return membersCount;
    }

    public List<Map<String, Object>> getTasks() {
        return tasks;
    }

    @Override
    public String toString() {
        ObjectMapper objectMapper = new ObjectMapper();
        try {
            return objectMapper.writeValueAsString(this);
        } catch (JsonProcessingException e) {
        }
        return "TaskModel{" +
                "dataId='" + dataId + '\'' +
                ", context='" + context + '\'' +
                ", type='" + type + '\'' +
                ", id='" + id + '\'' +
                ", name='" + name + '\'' +
                ", dataTime='" + dataTime + '\'' +
                ", completedTaskOverWritePolicy='" + completedTaskOverWritePolicy + '\'' +
                ", description='" + description + '\'' +
                ", lifeCycleEventOnTaskStateChange='" + lifeCycleEventOnTaskStateChange + '\'' +
                ", serviceEnabled='" + serviceEnabled + '\'' +
                ", status=" + status +
                ", members=" + members +
                ", membersCount='" + membersCount + '\'' +
                ", tasks=" + tasks +
                '}';
    }
}
